from typing import List


class Solution:
    def minDeletionSize(self, strs: List[str]) -> int:
        # 每个单词的长度
        m, n = len(strs), len(strs[0])
        ans = 0
        # 检查每一列
        for i in range(n):
            # 检查每一行
            for j in range(1, m):
                if strs[j][i] < strs[j - 1][i]:
                    ans += 1
                    break
        return ans


class Solution2(object):
    def minDeletionSize(self, A):
        ans = 0
        for col in zip(*A):
            if any(col[i] > col[i + 1] for i in range(len(col) - 1)):
                ans += 1
        return ans


if __name__ == '__main__':
    sol = Solution()
    print(sol.minDeletionSize(["abc", "bce", "cae"]))
    print(sol.minDeletionSize(["a", "b"]))
    print(sol.minDeletionSize(["zyx", "wvu", "    tsr"]))
